﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using ZX.SYS.Library;
using ZX.SYS.Bussiness.DeskTop;
using Newtonsoft.Json;
using ZX.Web.UI.Controls;

namespace ZX.WebApp.DeskTop.SetDesktop
{
    public partial class ModifyDeskTopTemp : System.Web.UI.Page
    {
        private string action = string.Empty;
        private string DeskTopTempID = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            action = Request["Oper"];
            switch (action)
            {
                case "Modify": Modify(); break;
            }
            if (!IsPostBack)
            {
                if (Request["Action"] == "add") return;
                DeskTopTempID = Request["DeskTopTempID"];
                LoadData();
            }
        }

        protected void LoadData()
        {
            SysDesktopTemplate sdt = new SysDesktopTemplate();
            sdt = BDeskTop.GetSysDesktopTemplateEntity(DeskTopTempID,"");
            txtDeskName.Value = sdt.DeskTopTempName;
            txtPath.Value = sdt.Src;
            txtHeight.Value = sdt.Height;
            ddlPageType.SelectedIndex = sdt.PageType;
        }

        protected void Modify()
        {
            DeskTopTempID = Request["DeskTopTempID"];
            string name = Request["DeskTopTempName"];
            string Src = Request["Src"];
            string Height = Request["Height"];
            string EntityName = Request["EntityName"];
            string sort = Request["sort"];
            string PageType = Request["PageType"];

            SysDesktopTemplate sdt = new SysDesktopTemplate();
            if (Request["Action"] == "add") { sdt.DeskTopTempID = Guid.NewGuid(); }
            else { sdt.DeskTopTempID = new Guid(DeskTopTempID); }

            sdt.DeskTopTempName = name;
            sdt.Src = Src;
            sdt.Height = Height;
            sdt.EntityName = EntityName;
            sdt.Sort = int.Parse(sort);
            sdt.PageType = int.Parse(PageType);

            string json = string.Empty;
            bool add = BDeskTop.ModifyDeskTopTemplate(sdt, Request["Action"]);
            if (add) json = JsonConvert.SerializeObject(sdt);
            Response.Clear();
            Response.ContentType = "application/json";
            Response.Write(json);
            Response.End();
        }
    }
}